import pymysql

class Sql(object):
    #数据库相关信息
    conn = pymysql.connect(
        host='127.0.0.1',
        port=3306,
        user='root',
        passwd='mysql',
        db='ccunews',
        charset='utf8')

    #将新闻信息添加到数据库中去
    """
    xueyuan:学院名称
    ls：序号
    newsll：新闻标题
    time：新闻发布时间
    src：新闻的网址，访问可以查看
    content：新闻的内容
    """
    def searchNews(self):
        cur=self.conn.cursor()
        cur.execute('select * from ccunews WHERE time>"2018/06/05" AND xueyuan="计算机科学技术学院"')
        results=cur.fetchall()#利用len可以直接获取查询到的数量
        print(len(results))
        for row in results:
            id = row[0]
            xueyuan = row[1]
            ls = row[2]
            newsl = row[3]
            time = row[4]
            src = row[5]
            content = row[6]
            # 打印结果
            print(id, xueyuan,ls , newsl, time,src,content)
            cur.close()  # 关闭游标

mysql=Sql()
mysql.searchNews()

"""
a="2019/01/01"
b="2018/03/22"
print(a>b)
"""